import time

import pandas as pd

import TimeUtil

import pppoe
from PD import PdUtil
import Batch

if __name__ == '__main__':
    date = TimeUtil.parse("2025-07-31")
    date_pre = "2025-06-30"
    a = time.time()
    res = []
    for chunk in pd.read_csv(pppoe.get_pppoe_by_date(date), usecols=[0, 4, 5, 10],
                             names=['宽带账号', 'OLTIP', 'OLTPORT', 'pppoe上线时间'],
                             dtype=str, chunksize=100000):
        filtered_chunk = chunk[chunk['pppoe上线时间'] > date_pre]
        res.append(filtered_chunk)
    res = pd.concat(res, ignore_index=True)
    # 根据pon统计账号个数，保留大于64的
    res = res.groupby(['OLTIP', 'OLTPORT']).agg(
        账号个数=('宽带账号', 'nunique')
    )
    res = res[res['账号个数'] > 64]
    print(time.time() - a)
    res = res.reset_index()
    res['pon'] = res['OLTIP'] + "/" + res['OLTPORT']
    PdUtil.to_csv(f"D:\\temp\\明细\\健康度{Batch.batch}\\超限pon.csv", res)
